<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("platinumgrid/jtplatinumgrid.inc.php");
use_unit("components4phpfull/jtgroupbox.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("components4phpfull/jtpagecontrol.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class Settings extends Page
{
       public $Image2 = null;
       public $Label1 = null;
       public $JTGroupEmailAlert = null;
       public $edAssetDescription = null;
       public $lblAssetDescription = null;
       public $edAssetIdentifiers = null;
       public $lblAssetIdentifiers = null;
       public $edMessageLine2 = null;
       public $lblMessageLine2 = null;
       public $edMessageLine1 = null;
       public $lblMessageLine1 = null;
       public $edSubjectLine = null;
       public $lblSubjectLine = null;
       public $JTGroupReminderOptions = null;
       public $chkWrite = null;
       public $chkCopy = null;
       public $edPrice = null;
       public $JTGroupDefaultMarkup = null;
       public $cmbDefInvMarkup = null;
       public $rbtnDefInvExpensing = null;
       public $JTGroupDefaultExpense = null;
       public $JTGroupBarcode = null;
       public $Edit1 = null;
       public $chkFavor = null;
       public $edPoints = null;
       public $lblPoints = null;
       public $lblStop = null;
       public $edStop = null;
       public $edStart = null;
       public $lblStart = null;
       public $lblFont = null;
       public $cmbType = null;
       public $lblType = null;
       public $JTGroupWorkOrders = null;
       public $lblAutoNumbering = null;
       public $edExceptFor = null;
       public $lblExceptFor = null;
       public $lblDays = null;
       public $edDays = null;
       public $lblNotify = null;
       public $edDefaultCharge = null;
       public $lblDefaultCharge = null;
       public $edLastOrderNo = null;
       public $lblLastOrderNo = null;
       public $edPrefix = null;
       public $lblPrefix = null;
       public $chkAutoNumbering = null;
       public $JTGroupFreeTagAxle = null;
       public $lblFreeReplace = null;
       public $edFreeReplaceAt = null;
       public $Label7 = null;
       public $lblFreeWarning = null;
       public $edFreeWarningAt = null;
       public $lblFreeWarningAt = null;
       public $JTGroupDriveAxle = null;
       public $lblDriveReplace = null;
       public $edDriveReplaceAt = null;
       public $lblDriveReplaceAt = null;
       public $lblDriveWarning = null;
       public $edDriveWarningAt = null;
       public $lblDriveWarningAt = null;
       public $JTGroupAxleSteer = null;
       public $lblSteerReplace = null;
       public $edAxleReplaceAt = null;
       public $lblAxleReplaceAt = null;
       public $lblSteerWarning = null;
       public $edAxleWarningAt = null;
       public $lblAxleWarningAt = null;
       public $JTGroupNewTireDefaults = null;
       public $cmbLocation = null;
       public $lblLocation = null;
       public $lblPressurePsi = null;
       public $edPressure = null;
       public $lblPressure = null;
       public $lblTread32nds = null;
       public $edTread = null;
       public $lblTread = null;
       public $lblPremium = null;
       public $edPremium = null;
       public $edPhone = null;
       public $lblPhone = null;
       public $lblCoverage = null;
       public $edCoverage = null;
       public $edAgent = null;
       public $lblAgent = null;
       public $edInsurance = null;
       public $lblInsurance = null;
       public $edAddress = null;
       public $lblAddress = null;
       public $lblCompany = null;
       public $edCompany = null;
       public $edPolicy = null;
       public $lblPolicy = null;
       public $hiddenModel = null;
       public $hiddenMnfr = null;
       public $btnModelDelete = null;
       public $btnModelUpdate = null;
       public $btnModelAdd = null;
       public $btnMnfrDelete = null;
       public $btnMnfrUpdate = null;
       public $btnMnfrAdd = null;
       public $btnCancel = null;
       public $btnSubmit = null;
       public $Label3 = null;
       public $editModel = null;
       public $editMnfr = null;
       public $Label2 = null;
       public $JTGridModel = null;
       public $JTGridMnfr = null;
       public $btnDelete_std = null;
       public $btnUpdate_std = null;
       public $btnAdd_std = null;
       public $edValue = null;
       public $lblTextValue = null;
       public $hiddenValueId = null;
       public $hiddenCategory = null;
       public $hiddenTable = null;
       public $JTValues = null;
       public $JTDroplists = null;
       public $JTPageControl2 = null;
       public $JTGroupDailyUtilization = null;
       public $edHoursSun = null;
       public $edHoursSat = null;
       public $edHoursFri = null;
       public $edHoursThu = null;
       public $edHoursWed = null;
       public $edHoursTue = null;
       public $edHoursMon = null;
       public $edMilesSun = null;
       public $edMilesSat = null;
       public $edMilesFri = null;
       public $edMilesThu = null;
       public $edMilesWed = null;
       public $edMilesTue = null;
       public $edMilesMon = null;
       public $lblHours = null;
       public $lblMiles = null;
       public $lblSun = null;
       public $lblSat = null;
       public $lbFri = null;
       public $lblThu = null;
       public $lblWed = null;
       public $lblTue = null;
       public $lblMon = null;
       public $JTGroupInventory = null;
       public $rbtnSellingPrice = null;
       public $JTGroupAuto = null;
       public $chkLabor = null;
       public $chkAuto = null;
       public $chkParts = null;
       public $chkMiscellaneous = null;
       public $chkLockAmount = null;
       public $chkLockRate = null;
       public $lblPercent = null;
       public $edPercent = null;
       public $JTGroupReminders = null;
       public $chkShowOrder = null;
       public $JTGroupScheduling = null;
       public $lblSchedulingHours = null;
       public $edSchedulingHours = null;
       public $lblSchedulingMiles = null;
       public $edSchedulingMiles = null;
       public $JTGroupAdvance = null;
       public $edAdvanceHours = null;
       public $edAdvanceDays = null;
       public $edAdvanceMiles = null;
       public $lblAdvanceHours = null;
       public $lblAdvanceDays = null;
       public $lblAdvanceMiles = null;
       public $JTGroupGauge = null;
       public $lblGaugesHours = null;
       public $cmbGaugeHours = null;
       public $lblGaugesDays = null;
       public $cmbGaugeDays = null;
       public $lblGaugesMiles = null;
       public $cmbGaugeMiles = null;
       public $memoInvoiceLegal = null;
       public $lblInvoiceLegal = null;
       public $Image1 = null;
       public $JTPageControl1 = null;
       function btnSubmitJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       window.close();
       <?php

       }


       function btnCancelJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       window.close();
       <?php

       }

       function cmbDefInvMarkupChange($sender, $params)
       {
       $markup=$this->cmbDefInvMarkup->getItemIndex();
       if ($markup=="Manual")
       {
       $this->edPrice->Enabled=false;
       }

       if ($markup=="Percent")
       {
       $this->edPrice->Enabled=true;
       }

       if ($markup=="Fixed Value")
       {
       $this->edPrice->Enabled=true;
       }
       }

       function chkAutoNumberingJSChange($sender, $params)
       {

       ?>
       //Add your javascript code here
       if(document.Settings.chkAutoNumbering.checked==true)
       {
       document.Settings.edPrefix.disabled=false;
       document.Settings.edLastOrderNo.disabled=false;
       }
       else
       {
       document.Settings.edPrefix.disabled=true;
       document.Settings.edLastOrderNo.disabled=true;
       }
       <?php

       }


       function JTGridMnfrShow($sender, $params)
       {
       $arr_mnfr = array();
       $result_mnfr = mysql_query("SELECT * FROM lookup_vehicle_tbl WHERE category='manufacturer'") or die("SELECT MNFR".mysql_error());
       while($row_mnfr = mysql_fetch_array($result_mnfr))
       {
         $mnfr_id = $row_mnfr['id'];
         $mnfr_value = $row_mnfr['value'];
         $mnfr_link = "<a href=Settings.php?layer=1&mnfr_id=".$mnfr_id.">".$mnfr_value."</a>";
         $arr_mnfr[] = array('Manufacturer' => $mnfr_link);
       }
         $this->JTGridMnfr->setCellData($arr_mnfr);

       }

       function JTGridModelShow($sender, $params)
       {
       $mnfr_id = $this->hiddenMnfr->getValue();
       $model_id = $this->hiddenModel->getValue();
       $arr_model = array();
       $result_model = mysql_query("SELECT * FROM lookup_models_tbl WHERE mnfr_id='".$mnfr_id."'") or die("SELECT MODEL".mysql_error());
       while($row_model = mysql_fetch_array($result_model))
       {
       $model_id = $row_model['id'];
       $model_value = $row_model['model_name'];
       $model_link = "<a href=Settings.php?mnfr_id=".$mnfr_id."&model_id=".$model_id.">".$model_value."</a>";
       $arr_model[] = array('Model' => $model_link);
       }
       $this->JTGridModel->setCellData($arr_model);
       }

       function btnModelDeleteClick($sender, $params)
       {
       $mnfr_id = $this->hiddenMnfr->getValue();
       $model_id = $this->hiddenModel->getValue();
       mysql_query("DELETE FROM lookup_models_tbl WHERE id='".$model_id."'");

       redirect('Settings.php?layer=1&mnfr_id='.$mnfr_id);
       }

       function btnModelUpdateClick($sender, $params)
       {
       $mnfr_id = $this->hiddenMnfr->getValue();
       $model_id = $this->hiddenModel->getValue();
       mysql_query("UPDATE lookup_models_tbl SET model_name='".$this->editModel->getText()."'
       WHERE id='".$model_id."'") or
       die("UPDATE MODEL".mysql_error());

       redirect("Settings.php?layer=1&mnfr_id=".$mnfr_id."&model_id=".$model_id);
       }

       function btnModelAddClick($sender, $params)
       {
       $mnfr_id = $this->hiddenMnfr->getValue();
       mysql_query("INSERT INTO lookup_models_tbl (mnfr_id, model_name)
       VALUES ('".$mnfr_id."','".$this->editModel->getText()."')") or
       die("INSERT MODEL".mysql_error());

       redirect('Settings.php?layer=1&mnfr_id='.$mnfr_id);
       }


       function btnMnfrDeleteClick($sender, $params)
       {
       $mnfr_id = $this->hiddenMnfr->getValue();
       mysql_query("DELETE FROM lookup_vehicle_tbl WHERE id='".$mnfr_id."'");

       redirect('Settings.php?layer=1&mnfr_id='.$mnfr_id);
       }

       function btnMnfrUpdateClick($sender, $params)
       {
       $mnfr_id = $this->hiddenMnfr->getValue();
       mysql_query("UPDATE lookup_vehicle_tbl SET value='".$this->editMnfr->getText()."'
       WHERE id='".$mnfr_id."'");

       redirect('Settings.php?layer=1&mnfr_id='.$mnfr_id);
       }

       function btnMnfrAddClick($sender, $params)
       {
       mysql_query("INSERT INTO lookup_vehicle_tbl
       (category, value) VALUES ('manufacturer','".$this->editMnfr->getText()."')") or
       die("INSERT MNFR".mysql_error());

       redirect('Settings.php?layer=1&mnfr_id='.$mnfr_id);
       }


       function btnDelete_stdClick($sender, $params)
       {
       $id = $this->hiddenValueId->getValue();
       $table = $this->hiddenTable->getValue();
       $category = $this->hiddenCategory->getValue();

       $query_delete = "DELETE FROM ".$table." WHERE id='".$id."'";
       mysql_query($query_delete) or die(mysql_error());
       redirect('Settings.php?save_to='.$table.'&category='.$category);
       }

       function btnUpdate_stdClick($sender, $params)
       {
       $id = $this->hiddenValueId->getValue();
       $table = $this->hiddenTable->getValue();
       $category = $this->hiddenCategory->getValue();

       $query_update = "UPDATE ".$table." SET
       value = '".$this->edValue->getText()."'
       WHERE id='".$id."'";
       mysql_query($query_update) or die(mysql_error());
       redirect('Settings.php?save_to='.$table.'&category='.$category);
       }

       function btnAdd_stdClick($sender, $params)
       {
       $id = $this->hiddenValueId->getValue();
       $table = $this->hiddenTable->getValue();
       $category = $this->hiddenCategory->getValue();
       $result_values = mysql_query("INSERT INTO ".$table."(id, value,category) VALUES (
       '".$this->hiddenValueId->getValue()."',
       '".$this->edValue->getText()."',
       '".$category."'
       )")or die("INSERT VALUE - " . mysql_error());
       redirect('Settings.php?save_to='.$table.'&category='.$category.'&id='.$id);

       }

       function chkAutoJSChange($sender, $params)
       {

       ?>
       //Add your javascript code here
       if(document.Settings.chkAuto.checked == true)
       {
       document.Settings.chkLabor.disabled = false;
       document.Settings.chkMiscellaneous.disabled = false;
       document.Settings.chkParts.disabled = false;
       document.Settings.edPercent.disabled = false;
       document.Settings.edPercent.style.background =  '#FFFFFF';
       document.Settings.chkLockRate.disabled = false;
       document.Settings.chkLockAmount.disabled = false;
       }
       else
       {
       document.Settings.chkLabor.disabled = true;
       document.Settings.chkMiscellaneous.disabled = true;
       document.Settings.chkParts.disabled = true;
       document.Settings.chkLockRate.disabled = true;
       document.Settings.chkLockAmount.disabled = true;
       document.Settings.edPercent.disabled = true;
       document.Settings.edPercent.style.background =  '#EFEFEF';
       }
       <?php

       }

       function btnSubmitClick($sender, $params)
       {
       //LEGAL
       $result_legal=mysql_query("SELECT * FROM company_legal_tbl WHERE company_id='".$_SESSION['company_id']."'");
       $legal_count=mysql_num_rows($result_legal);
       if($legal_count==0)
       {
       mysql_query("INSERT INTO company_legal_tbl (company_id,
       invoice_legal)

       VALUES('".$_SESSION['company_id']."',
       '".$this->memoInvoiceLegal->Text."')") or die ("insert legal - " . mysql_error());
       }
       else
       {
       mysql_query("UPDATE company_legal_tbl SET
       invoice_legal='".$this->memoInvoiceLegal->Text."'
       WHERE company_id='".$_SESSION['company_id']."'") or die ("UPDATE LEGAl - " . mysql_error());
       }

       //GAUGES
       if ($this->chkShowOrder->Checked==true)
       {
       $chkShowOrder ='1';
       }
       else
       {
       $chkShowOrder='0';
       }

       $result_gauges=mysql_query("SELECT * FROM company_gauges_tbl WHERE company_id='".$_SESSION['company_id']."'");
       $gauges_count=mysql_num_rows($result_gauges);
       if($gauges_count==0)
       {
       mysql_query("INSERT INTO company_gauges_tbl (company_id,
       gauge_miles,
       gauge_days,
       gauge_hours,
       advance_miles,
       advance_days,
       advance_hours,
       scheduling_miles,
       scheduling_hours,
       show_order)

       VALUES('".$_SESSION['company_id']."',
       '".$this->cmbGaugeMiles->getItemIndex()."',
       '".$this->cmbGaugeDays->getItemIndex()."',
       '".$this->cmbGaugeHours->getItemIndex()."',
       '".$this->edAdvanceMiles->Text."',
       '".$this->edAdvanceDays->Text."',
       '".$this->edAdvanceHours->Text."',
       '".$this->edSchedulingMiles->Text."',
       '".$this->edSchedulingHours->Text."',
       '".$chkShowOrder."')") or die ("INSERT GAUGES - " . mysql_error());
       }
       else
       {
       mysql_query("UPDATE company_gauges_tbl SET
       gauge_miles='".$this->cmbGaugeMiles->getItemIndex()."',
       gauge_days='".$this->cmbGaugeDays->getItemIndex()."',
       gauge_hours='".$this->cmbGaugeHours->getItemIndex()."',
       advance_miles='".$this->edAdvanceMiles->Text."',
       advance_days='".$this->edAdvanceDays->Text."',
       advance_hours='".$this->edAdvanceHours->Text."',
       scheduling_miles='".$this->edSchedulingMiles->Text."',
       scheduling_hours='".$this->edSchedulingHours->Text."',
       show_order='".$chkShowOrder."'
       WHERE company_id='".$_SESSION['company_id']."'") or die ("UPDATE GAUGES - " . mysql_error());
       }

       //BILLING
       if ($this->chkAuto->Checked==true)
       {
       $chkAuto='1';
       }
       else
       {
       $chkAuto='0';
       }

       if ($this->chkLabor->Checked==true)
       {
       $chkLabor='1';
       }
       else
       {
       $chkLabor='0';
       }

       if ($this->chkMiscellaneous->Checked==true)
       {
       $chkMiscellaneous='1';
       }
       else
       {
       $chkMiscellaneous='0';
       }

       if ($this->chkParts->Checked==true)
       {
       $chkParts='1';
       }
       else
       {
       $chkParts='0';
       }

       if ($this->chkLockRate->Checked==true)
       {
       $chkLockRate='1';
       }
       else
       {
       $chkLockRate='0';
       }

       if ($this->chkLockAmount->Checked==true)
       {
       $chkLockAmount ='1';
       }
       else
       {
       $chkAmount='0';
       }

       $result_billing=mysql_query("SELECT * FROM company_billing_tbl WHERE company_id='".$_SESSION['company_id']."'");
       $billing_count=mysql_num_rows($result_billing);
       if($billing_count==0)
       {
       mysql_query("INSERT INTO company_billing_tbl (company_id,
       automatically_calculate,
       percent,
       labor,
       miscellaneous,
       parts,
       lock_tax_rate,
       lock_tax_amount,
       selling_price)

       VALUES('".$_SESSION['company_id']."',
       '".$chkAuto."',
       '".$this->edPercent->Text."',
       '".$chkLabor."',
       '".$chkMiscellaneous."',
       '".$chkParts."',
       '".$chkLockRate."',
       '".$chkLockAmount."',
       '".$this->rbtnSellingPrice->getItemIndex()."')") or die ("INSERT BILLING - " . mysql_error());
       }
       else
       {
       mysql_query("UPDATE company_billing_tbl SET
       automatically_calculate='".$chkAuto."',
       percent='".$this->edPercent->Text."',
       labor='".$chkLabor."',
       miscellaneous='".$chkMiscellaneous."',
       parts='".$chkParts."',
       lock_tax_rate='".$chkLockRate."',
       lock_tax_amount='".$chkLockAmount."',
       selling_price='".$this->rbtnSellingPrice->getItemIndex()."'
       WHERE company_id='".$_SESSION['company_id']."'") or die ("UPDATE BILLING - " . mysql_error());
       }

       //ASSET UTILIZATION
       $result_asset=mysql_query("SELECT * FROM company_asset_tbl WHERE company_id='".$_SESSION['company_id']."'");
       $asset_count=mysql_num_rows($result_asset);
       if($asset_count==0)
       {
       mysql_query("INSERT INTO company_asset_tbl (company_id,
       miles_mon,
       miles_tue,
       miles_wed,
       miles_thu,
       miles_fri,
       miles_sat,
       miles_sun,
       hours_mon,
       hours_tue,
       hours_wed,
       hours_thu,
       hours_fri,
       hours_sat,
       hours_sun)

       VALUES('".$_SESSION['company_id']."',
       '".$this->edMilesMon->Text."',
       '".$this->edMilesTue->Text."',
       '".$this->edMilesWed->Text."',
       '".$this->edMilesThu->Text."',
       '".$this->edMilesFri->Text."',
       '".$this->edMilesSat->Text."',
       '".$this->edHoursMon->Text."',
       '".$this->edHoursTue->Text."',
       '".$this->edHoursWed->Text."',
       '".$this->edHoursTue->Text."',
       '".$this->edHoursThu->Text."',
       '".$this->edHoursFri->Text."',
       '".$this->edHoursSat->Text."',
       '".$this->edHoursSun->Text."')") or die ("INSERT ASSET - " . mysql_error());
       }
       else
       {
       mysql_query("UPDATE company_asset_tbl SET
       miles_mon='".$this->edMilesMon->Text."',
       miles_tue='".$this->edMilesTue->Text."',
       miles_wed='".$this->edMilesWed->Text."',
       miles_thu='".$this->edMilesThu->Text."',
       miles_fri='".$this->edMilesFri->Text."',
       miles_sat='".$this->edMilesSat->Text."',
       hours_mon='".$this->edHoursMon->Text."',
       hours_tue='".$this->edHoursTue->Text."',
       hours_wed='".$this->edHoursWed->Text."',
       hours_thu='".$this->edHoursThu->Text."',
       hours_fri='".$this->edHoursFri->Text."',
       hours_sat='".$this->edHoursSat->Text."',
       hours_sun='".$this->edHoursSun->Text."'
       WHERE company_id='".$_SESSION['company_id']."'") or die ("UPDATE ASSET - " . mysql_error());
       }

       //INSURANCE
       $result_insurance=mysql_query("SELECT * FROM company_insurance_tbl WHERE company_id='".$_SESSION['company_id']."'");
       $insurance_count=mysql_num_rows($result_insurance);
       if($insurance_count==0)
       {
       mysql_query("INSERT INTO company_insurance_tbl (company_id,
       policy_no,
       company_name,
       address,
       insurance_company,
       agent,
       contact_no,
       coverage_limits,
       premium)

       VALUES('".$_SESSION['company_id']."',
       '".$this->edPolicy->Text."',
       '".$this->edCompany->Text."',
       '".$this->edAddress->Text."',
       '".$this->edInsurance->Text."',
       '".$this->edAgent->Text."',
       '".$this->edPhone->Text."',
       '".$this->edCoverage->Text."',
       '".$this->edPremium->Text."')") or die ("INSERT INSURANCE - " . mysql_error());
       }
       else
       {
       mysql_query("UPDATE company_insurance_tbl SET
       policy_no='".$this->edPolicy->Text."',
       company_name='".$this->edCompany->Text."',
       address='".$this->edAddress->Text."',
       insurance_company='".$this->edInsurance->Text."',
       agent='".$this->edAgent->Text."',
       contact_no='".$this->edPhone->Text."',
       coverage_limits='".$this->edCoverage->Text."',
       premium='".$this->edPremium->Text."'
       WHERE company_id='".$_SESSION['company_id']."'") or die ("UPDATE INSURANCE - " . mysql_error());
       }

       //TIRES
       $result_tires=mysql_query("SELECT * FROM company_tires_tbl WHERE company_id='".$_SESSION['company_id']."'");
       $tires_count=mysql_num_rows($result_tires);
       if($tires_count==0)
       {
       mysql_query("INSERT INTO company_tires_tbl (company_id,
       tread,
       pressure,
       location,
       steer_warning,
       steer_replace,
       drive_warning,
       drive_replace,
       free_warning,
       free_replace)

       VALUES('".$_SESSION['company_id']."',
       '".$this->edTread->Text."',
       '".$this->edPressure->Text."',
       '".$this->cmbLocation->getItemIndex()."',
       '".$this->edAxleWarningAt->Text."',
       '".$this->edAxleReplaceAt->Text."',
       '".$this->edDriveWarningAt->Text."',
       '".$this->edDriveReplaceAt->Text."',
       '".$this->edFreeWarningAt->Text."',
       '".$this->edFreeReplaceAt->Text."')") or die ("INSERT TIRES - " . mysql_error());
       }
       else
       {
       mysql_query("UPDATE company_tires_tbl SET
       tread='".$this->edTread->Text."',
       pressure='".$this->edPressure->Text."',
       location='".$this->cmbLocation->getItemIndex()."',
       steer_warning='".$this->edAxleWarningAt->Text."',
       steer_replace='".$this->edAxleReplaceAt->Text."',
       drive_warning='".$this->edDriveWarningAt->Text."',
       drive_replace='".$this->edDriveReplaceAt->Text."',
       free_warning='".$this->edFreeWarningAt->Text."',
       free_replace='".$this->edFreeReplaceAt->Text."'
       WHERE company_id='".$_SESSION['company_id']."'") or die ("UPDATE TIRES - " . mysql_error());

       }

       //WORK ORDERS
       if ($this->chkAutoNumbering->Checked==true)
       {
       $chkAutoNumbering ='1';
       }
       else
       {
       $chkAutoNumbering='0';
       }

       if ($this->chkFavor->Checked==true)
       {
       $chkFavor='1';
       }
       else
       {
       $chkFavor='0';
       }

       $result_workorders=mysql_query("SELECT * FROM company_workorders_tbl WHERE company_id='".$_SESSION['company_id']."'");
       $workorders_count=mysql_num_rows($result_workorders);
       if($workorders_count==0)
       {
       mysql_query("INSERT INTO company_workorders_tbl (company_id,
       auto_numbering,
       prefix,
       last_order_no,
       default_charge,
       days,
       except_for,
       default_inv_expense,
       default_inv_markup,
       type,
       price,
       favor_stock_no)

       VALUES('".$_SESSION['company_id']."',
       '".$chkAutoNumbering."',
       '".$this->edPrefix->Text."',
       '".$this->edLastOrderNo->Text."',
       '".$this->edDefaultCharge->Text."',
       '".$this->edDays->Text."',
       '".$this->edExceptFor->Text."',
       '".$this->rbtnDefInvExpensing->getItemIndex()."',
       '".$this->cmbDefInvMarkup->getItemIndex()."',
       '".$this->cmbType->getItemIndex()."',
       '".$this->edPrice->Text."',
       '".$chkFavor."')") or die ("INSERT WORKORDERS - " . mysql_error());
       }
       else
       {
       mysql_query("UPDATE company_workorders_tbl SET
       auto_numbering='".$chkAutoNumbering."',
       prefix='".$this->edPrefix->Text."',
       last_order_no='".$this->edLastOrderNo->Text."',
       default_charge='".$this->edDefaultCharge->Text."',
       days='".$this->edDays->Text."',
       except_for='".$this->edExceptFor->Text."',
       default_inv_expense='".$this->rbtnDefInvExpensing->getItemIndex()."',
       default_inv_markup='".$this->cmbDefInvMarkup->getItemIndex()."',
       type='".$this->cmbType->getItemIndex()."',
       price='".$this->edPrice->Text."',
       favor_stock_no='".$chkFavor."'
       WHERE company_id='".$_SESSION['company_id']."'") or die ("UPDATE WORKORDERS - " . mysql_error());
       }

       //REMINDERS
       if ($this->chkCopy->Checked==true)
       {
       $chkCopy ='1';
       }
       else
       {
       $chkCopy='0';
       }

       if ($this->chkWrite->Checked==true)
       {
       $chkWrite ='1';
       }
       else
       {
       $chkWrite ='0';
       }

       $result_reminders=mysql_query("SELECT * FROM company_reminders_tbl WHERE company_id='".$_SESSION['company_id']."'");
       $reminders_count=mysql_num_rows($result_reminders);
       if($reminders_count==0)
       {
       mysql_query("INSERT INTO company_reminders_tbl (company_id,
       copy_reminder,
       write_completion,
       subject_line,
       message_line1,
       message_line2,
       asset_identifiers,
       asset_description)

       VALUES('".$_SESSION['company_id']."',
       '".$chkCopy."',
       '".$chkWrite."',
       '".$this->edSubjectLine->Text."',
       '".$this->edMessageLine1->Text."',
       '".$this->edMessageLine2->Text."',
       '".$this->edAssetIdentifiers->Text."',
       '".$this->edAssetDescription->Text."')") or die ("INSERT REMINDERS - " . mysql_error());
       }
       else
       {
       mysql_query("UPDATE company_reminders_tbl SET
       copy_reminder='".$chkCopy."',
       write_completion='".$chkWrite."',
       subject_line='".$this->edSubjectLine->Text."',
       message_line1='".$this->edMessageLine1->Text."',
       message_line2='".$this->edMessageLine2->Text."',
       asset_identifiers='".$this->edAssetIdentifiers->Text."',
       asset_description='".$this->edAssetDescription->Text."'
       WHERE company_id='".$_SESSION['company_id']."'") or die ("UPDATE REMINDERS - " . mysql_error());
       }

       //redirect('vehicle_list.php?company_id='.$_SESSION['company_id']);
       //redirect('main.php?company_id='.$_SESSION['company_id']);
       }

       function SettingsCreate($sender, $params)
       {
       //LEGAL
       $query_legal = "SELECT * FROM company_legal_tbl WHERE company_id='".$_SESSION['company_id']."'";
       $result_legal_show = mysql_query($query_legal)or die("SELECT LEGAL - " . mysql_error());
       $row_legal= mysql_fetch_array($result_legal_show);

       $this->memoInvoiceLegal->Text = $row_legal['invoice_legal'];

       //GAUGES
       $query_gauges = "SELECT * FROM company_gauges_tbl WHERE company_id= '".$_SESSION['company_id']."'";
       $result_gauges_show = mysql_query($query_gauges)or die("SELECT GAUGES - " . mysql_error());
       $row_gauges= mysql_fetch_array($result_gauges_show);

       if($row_gauges['show_order']=='1')
       {
       $this->chkShowOrder->Checked=true;
       }
       else
       {
       $this->chkShowOrder->Checked=false;
       }
       $this->cmbGaugeMiles->ItemIndex = $row_gauges['gauge_miles'];
       $this->cmbGaugeHours->ItemIndex = $row_gauges['gauge_hours'];
       $this->cmbGaugeDays->ItemIndex = $row_gauges['gauge_days'];
       $this->edAdvanceMiles->Text = $row_gauges['advance_miles'];
       $this->edAdvanceDays->Text = $row_gauges['advance_days'];
       $this->edAdvanceHours->Text = $row_gauges['advance_hours'];
       $this->edSchedulingMiles->Text = $row_gauges['scheduling_miles'];
       $this->edSchedulingHours->Text = $row_gauges['scheduling_hours'];

       $result_unit = mysql_query("SELECT * FROM company_measures_tbl WHERE company_id='".$_SESSION['company_id']."'");
       $row_unit = mysql_fetch_array($result_unit);
       $label_unit = $row_unit['system_measure'];

       if($label_unit=='Metric Measurement (km, Liters, L100 km)')
       {
       $this->lblGaugesMiles->Caption = 'km';
       $this->lblAdvanceMiles->Caption = 'km';
       $this->lblSchedulingMiles->Caption = 'km';
       }
       else
       {
       $this->lblGaugesMiles->Caption = 'Miles';
       $this->lblAdvanceMiles->Caption = 'Miles';
       $this->lblSchedulingMiles->Caption = 'Miles';
       }

       //BILLING
       $query_billing = "SELECT * FROM company_billing_tbl WHERE company_id='".$_SESSION['company_id']."'";
       $result_billing_show = mysql_query($query_billing)or die("SELECT BILLING - " . mysql_error());
       $row_billing= mysql_fetch_array($result_billing_show);

       if($row_billing['automatically_calculate']=='1')
       {
       $this->chkAuto->Checked=true;
       }
       else
       {
       $this->chkAuto->Checked=false;
       }

       if($row_billing['labor']=='1')
       {
       $this->chkLabor->Checked=true;
       }
       else
       {
       $this->chkLabor->Checked=false;
       }

       if($row_billing['miscellaneous']=='1')
       {
       $this->chkMiscellaneous->Checked=true;
       }
       else
       {
       $this->chkMiscellaneous->Checked=false;
       }

       if($row_billing['parts']=='1')
       {
       $this->chkParts->Checked=true;
       }
       else
       {
       $this->chkParts->Checked=false;
       }

       if($row_billing['lock_tax_rate']=='1')
       {
       $this->chkLockRate->Checked=true;
       }
       else
       {
       $this->chkLockRate->Checked=false;
       }

       if($row_billing['lock_tax_amount']=='1')
       {
       $this->chkLockAmount->Checked=true;
       }
       else
       {
       $this->chkLockAmount->Checked=false;
       }

       $this->rbtnSellingPrice->ItemIndex = $row_billing['selling_price'];
       $this->edPercent->Text = $row_billing['percent'];

       $this->chkLabor->Enabled = false;
       $this->chkMiscellaneous->Enabled = false;
       $this->chkParts->Enabled = false;
       $this->edPercent->Enabled =false;
       $this->edPercent->Color = EFEFEF;
       $this->chkLockRate->Enabled = false;
       $this->chkLockAmount->Enabled = false;

       //ASSET UTILIZATION
       $query_asset = "SELECT * FROM company_asset_tbl WHERE company_id='".$_SESSION['company_id']."'";
       $result_asset_show = mysql_query($query_asset)or die("SELECT ASSET - " . mysql_error());
       $row_asset= mysql_fetch_array($result_asset_show);

       $this->edMilesMon->Text = $row_asset['miles_mon'];
       $this->edMilesTue->Text = $row_asset['miles_tue'];
       $this->edMilesWed->Text = $row_asset['miles_wed'];
       $this->edMilesThu->Text = $row_asset['miles_thu'];
       $this->edMilesFri->Text = $row_asset['miles_fri'];
       $this->edMilesSat->Text = $row_asset['miles_sat'];
       $this->edMilesSun->Text = $row_asset['miles_sun'];
       $this->edHoursMon->Text = $row_asset['hours_mon'];
       $this->edHoursTue->Text = $row_asset['hours_tue'];
       $this->edHoursWed->Text = $row_asset['hours_wed'];
       $this->edHoursThu->Text = $row_asset['hours_thu'];
       $this->edHoursFri->Text = $row_asset['hours_fri'];
       $this->edHoursSat->Text = $row_asset['hours_sat'];
       $this->edHoursSun->Text = $row_asset['hours_sun'];

       //DROPLIST VALUES
       $table = null;
       $category = null;
       $id = null;
       $this->hiddenValueId->setValue($_GET['id']);
       $this->hiddenTable->setValue($_GET['save_to']);
       $this->hiddenCategory->setValue($_GET['category']);
       $table = $this->hiddenTable->getValue();
       $category = $this->hiddenCategory->getValue();

       $this->JTPageControl2->TabIndex = $_GET['layer'];

       $fields_array = array('Expense Accounts', 'Expense Descriptions', 'Expense Types',
       'Fuel Brands', 'Fuel Dealer Names', 'Fuel Octane/Types',
       'Fuel State/Province', 'Inventory Adj Reasons', 'Inventory Manufacturers',
       'Inventory Storeroom/Locations', 'Inventory Types', 'Inventory Unit of Measure',
       'Job Payment Types', 'Parts Descriptions', 'Parts Non-Stock Part Nos',
       'Parts Vendors', 'Personnel Departments', 'Personnel Driving History Types',
       'Personnel Job Grades', 'Personnel Job Titles', 'Personnel Renewals/Certifications',
       'Personnel Training/Certification Types', 'Personnel Work Locations', 'Template Types',
       'Tire Locations', 'Tire Manufacturers', 'Tire Sizes',
       'Tire Types', 'Tire Services Types', 'Tire Wheel Sizes',
       'Vehicle Body Styles', 'Vehicle Manufacturers', 'Vehicle Ownership',
       'Vehicle Journal Categories', 'Work Order Descriptions', 'Work Order Serviced By',
       'Work Order Task Descriptions', 'Work Order Type');

       $category_array = array('accounts', 'descriptions', 'types',
       'brands', 'dealer names', 'octane/types',
       'state/province', 'adj reasons', 'manufacturers',
       'storeroom/locations', 'types', 'unit of measure',
       'payment types', 'descriptions', 'non-stock part nos',
       'vendors', 'departments', 'driving history types',
       'job grades', 'job titles', 'renewals/certifications',
       'training/certification types', 'work locations', 'types',
       'locations', 'manufacturers', 'sizes',
       'types', 'services types', 'wheel sizes',
       'body styles', 'manufacturers', 'ownership',
       'journal categories', 'descriptions', 'serviced by',
       'task descriptions', 'type');

       $tbl_array = array('lookup_expense_tbl', 'lookup_expense_tbl', 'lookup_expense_tbl',
       'lookup_fuel_tbl', 'lookup_fuel_tbl', 'lookup_fuel_tbl',
       'lookup_fuel_tbl', 'lookup_inventory_tbl', 'lookup_inventory_tbl',
       'lookup_inventory_tbl', 'lookup_inventory_tbl', 'lookup_inventory_tbl',
       'lookup_job_tbl', 'lookup_parts_tbl', 'lookup_parts_tbl',
       'lookup_parts_tbl', 'lookup_personnel_tbl', 'lookup_personnel_tbl',
       'lookup_personnel_tbl', 'lookup_personnel_tbl', 'lookup_personnel_tbl',
       'lookup_personnel_tbl', 'lookup_personnel_tbl', 'lookup_template_tbl',
       'lookup_tire_tbl', 'lookup_tire_tbl', 'lookup_tire_tbl',
       'lookup_tire_tbl', 'lookup_tire_tbl', 'lookup_tire_tbl',
       'lookup_vehicle_tbl', 'lookup_vehicle_tbl', 'lookup_vehicle_tbl',
       'lookup_vehicle_tbl', 'lookup_workorder_tbl', 'lookup_workorder_tbl',
       'lookup_workorder_tbl', 'lookup_workorder_tbl');

       $arr = array();
       $ctr = 0;
       $count = count($fields_array);
       while($ctr<=$count)
       {
        $tools = "<a href='Settings.php?save_to=".$tbl_array[$ctr]."&category=".$category_array[$ctr]."'>".$fields_array[$ctr]."</a>";
        $arr[] = array('Drop list Fields ' => $tools);
        $ctr++;
       }
       $this->JTDroplists->setCellData($arr);

       if($table!=null)
       {
       $ctr = 0;
       $arr2 = array();
       $query2 = "SELECT * FROM ".$table." WHERE category='".$category."'";
       $result_values = mysql_query($query2);
       while($row_values = mysql_fetch_array($result_values))
       {
        $id = $row_values['id'];
        $value = "<a href='Settings.php?save_to=".$table."&id=".$id."&category=".$category."'>".$row_values['value']."</a>";
        $arr2[] = array('Values'=>$value);
        $ctr++;

       $query_select_value = "SELECT * FROM  ".$table." WHERE id='".$this->hiddenValueId->getValue()."'";
       $result_select_value = mysql_query($query_select_value) or die(mysql_error());
       $row_select_value = mysql_fetch_array($result_select_value);
       $this->edValue->setText($row_select_value['value']);
       }
       $this->JTValues->setCellData($arr2);
       }

       $this->hiddenMnfr->setValue($_GET['mnfr_id']);
       $this->hiddenModel->setValue($_GET['model_id']);
       $mnfr_id = $this->hiddenMnfr->getValue();
       $model_id = $this->hiddenModel->getValue();

       $result_mnfr = mysql_query("SELECT * FROM lookup_vehicle_tbl WHERE id='".$mnfr_id."'")
       or die("SELECT MNFR".mysql_error());
       $row_mnfr = mysql_fetch_array($result_mnfr);

       $result_model = mysql_query("SELECT * FROM lookup_models_tbl WHERE id='".$model_id."'") or
       die("SELECT MODEL".mysql_error());
       $row_model = mysql_fetch_array($result_model);

       $this->editMnfr->setText($row_mnfr['value']);
       $this->editModel->setText($row_model['model_name']);

       //INSURANCE
       $query_insurance = "SELECT * FROM company_insurance_tbl WHERE company_id='".$_SESSION['company_id']."'";
       $result_insurance_show = mysql_query($query_insurance)or die("SELECT INSURANCE - " . mysql_error());
       $row_insurance= mysql_fetch_array($result_insurance_show);

       $this->edPolicy->Text = $row_insurance['policy_no'];
       $this->edCompany->Text = $row_insurance['company_name'];
       $this->edAddress->Text = $row_insurance['address'];
       $this->edInsurance->Text = $row_insurance['insurance_company'];
       $this->edAgent->Text = $row_insurance['agent'];
       $this->edPhone->Text = $row_insurance['contact_no'];
       $this->edCoverage->Text = $row_insurance['coverage_limits'];
       $this->edPremium->Text = $row_insurance['premium'];

       //TIRES
       $query_tires = "SELECT * FROM company_tires_tbl WHERE company_id='".$_SESSION['company_id']."'";
       $result_tires_show = mysql_query($query_tires)or die("SELECT TIRES - " . mysql_error());
       $row_tires= mysql_fetch_array($result_tires_show);

       $this->edTread->Text = $row_tires['tread'];
       $this->edPressure->Text = $row_tires['pressure'];
       $this->edAxleWarningAt->Text = $row_tires['steer_warning'];
       $this->edAxleReplaceAt->Text = $row_tires['steer_replace'];
       $this->edDriveWarningAt->Text = $row_tires['drive_warning'];
       $this->edDriveReplaceAt->Text = $row_tires['drive_replace'];
       $this->edFreeWarningAt->Text = $row_tires['free_warning'];
       $this->edFreeReplaceAt->Text = $row_tires['free_replace'];

       $result_measures = mysql_query("SELECT * FROM company_measures_tbl WHERE company_id='".$_SESSION['company_id']."'");
       $row_measures = mysql_fetch_array($result_measures);
       $label_measures = $row_measures['system_measure'];
       if (($label_measures=='Metric Measurement (km, Liters, L100 km)') ||($label_measures=='U.K. Measurement (Miles, Litres, MPG)'))
        {
        $this->lblTread32nds->Caption = 'mm';
        $this->lblPressurePsi->Caption = 'kpa';
        $this->lblSteerWarning->Caption = 'mm';
        $this->lblSteerReplace->Caption = 'mm';
        $this->lblDriveWarning->Caption = 'mm';
        $this->lblDriveReplace->Caption = 'mm';
        $this->lblFreeWarning->Caption = 'mm';
        $this->lblFreeReplace->Caption = 'mm';
       }
       else
       {
        $this->lblTread32nds->Caption = '32nds';
        $this->lblPressurePsi->Caption = 'psi';
        $this->lblSteerWarning->Caption = '32nds';
        $this->lblSteerReplace->Caption = '32nds';
        $this->lblDriveWarning->Caption = '32nds';
        $this->lblDriveReplace->Caption = '32nds';
        $this->lblFreeWarning->Caption = '32nds';
        $this->lblFreeReplace->Caption = '32nds';
       }

       //WORK ORDERS
       $query_workorders = "SELECT * FROM company_workorders_tbl WHERE company_id='".$_SESSION['company_id']."'";
       $result_workorders_show = mysql_query($query_workorders)or die("SELECT WORKORDERS- " . mysql_error());
       $row_workorders= mysql_fetch_array($result_workorders_show);

       if($row_workorders['auto_numbering']=='1')
       {
       $this->chkAutoNumbering->Checked=true;
       }
       else
       {
       $this->chkAutoNumbering->Checked=false;
       }

       if($row_workorders['favor_stock_no']=='1')
       {
       $this->chkFavor->Checked=true;
       }
       else
       {
       $this->chkFavor->Checked=false;
       }

       $this->cmbType->ItemIndex = $row_workorders['type'];
       $this->rbtnDefInvExpensing->ItemIndex = $row_workorders['default_inv_expense'];
       $this->cmbDefInvMarkup->ItemIndex = $row_workorders['default_inv_markup'];
       $this->edPrefix->Text = $row_workorders['prefix'];
       $this->edLastOrderNo->Text = $row_workorders['last_order_no'];
       $this->edDefaultCharge->Text = $row_workorders['default_charge'];
       $this->edDays->Text = $row_workorders['days'];
       $this->edExceptFor->Text = $row_workorders['except_for'];
       $this->edPrice->Text = $row_workorders['price'];

       $this->edPrefix->Enabled=false;
       $this->edPrefix->Color= EFEFEF;
       $this->edLastOrderNo->Enabled=false;
       $this->edLastOrderNo->Color= EFEFEF;
       $this->edPrice->Enabled=false;
       $this->edPrice->Color= EFEFEF;

       //REMINDERS
       $query_reminders = "SELECT * FROM company_reminders_tbl WHERE company_id='".$_SESSION['company_id']."'";
       $result_reminders_show = mysql_query($query_reminders)or die("SELECT TIRES - " . mysql_error());
       $row_reminders= mysql_fetch_array($result_reminders_show);

      if($row_reminders['copy_reminder']=='1')
      {
      $this->chkCopy->Checked=true;
      }
      else
      {
      $this->chkCopy->Checked=false;
      }

      if($row_reminders['write_completion']=='1')
      {
      $this->chkWrite->Checked=true;
      }
      else
      {
      $this->chkWrite->Checked=false;
      }

      $this->edSubjectLine->Text = $row_reminders['subject_line'];
      $this->edMessageLine1->Text = $row_reminders['message_line2'];
      $this->edMessageLine2->Text = $row_reminders['message_line2'];
      $this->edAssetIdentifiers->Text = $row_reminders['asset_identifiers'];
      $this->edAssetDescription->Text = $row_reminders['asset_description'];
      }




}

global $application;

global $Settings;

//Creates the form
$Settings=new settings($application);

//Read from resource file
$Settings->loadResource(__FILE__);

//Shows the form
$Settings->show();

?>